const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('file', {
    id: {
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true
    },
    path_name: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "文件路径"
    },
    file_name: {
      type: DataTypes.STRING(255),
      allowNull: false,
      comment: "文件名"
    },
    new_name: {
      type: DataTypes.STRING(45),
      allowNull: false,
      comment: "实际存放的名字"
    },
    suffix_name: {
      type: DataTypes.STRING(45),
      allowNull: false,
      comment: "文件后缀名"
    },
    size: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: "文件大小"
    },
    creator: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: "创建者",
      references: {
        model: 'user',
        key: 'id'
      }
    },
    permissions: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "访问权限"
    },
    creattime: {
      type: DataTypes.DATEONLY,
      allowNull: true,
      comment: "创建时间"
    },
    moditime: {
      type: DataTypes.DATEONLY,
      allowNull: true,
      comment: "创建时间，上次修改时间，由触发器生成"
    },
    type: {
      type: DataTypes.STRING(100),
      allowNull: true
    }
  }, {
    sequelize,
    tableName: 'file',
    hasTrigger: true,
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "file_user_idx",
        using: "BTREE",
        fields: [
          { name: "creator" },
        ]
      },
    ]
  });
};
